package com.neusoft.neuiotms.support.mongo.converter;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Component;

import com.neusoft.bizcore.web.bean.LogBean;
import com.neusoft.neuiotms.support.mongo.model.LogDocument;

@Component
@ConditionalOnClass(MongoTemplate.class)
public class LogConverter {
    public LogDocument toDoc(LogBean bean) {
        final LogDocument doc = new LogDocument();
        doc.setApp(bean.getApp());
        doc.setRef(bean.getRef());
        doc.setAccount(bean.getAccount());
        doc.setUsername(bean.getUsername());
        doc.setIp(bean.getIp());
        doc.setOperation(bean.getOperation());
        doc.setApi(bean.getApi());
        doc.setExtra(bean.getExtra());
        doc.setTime(bean.getTime());
        return doc;
    }

    public LogBean toBean(LogDocument doc) {
        final LogBean bean = new LogBean();
        bean.setId(doc.getId());
        bean.setApp(doc.getApp());
        bean.setRef(doc.getRef());
        bean.setAccount(doc.getAccount());
        bean.setUsername(doc.getUsername());
        bean.setIp(doc.getIp());
        bean.setOperation(doc.getOperation());
        bean.setApi(doc.getApi());
        bean.setExtra(doc.getExtra());
        bean.setTime(doc.getTime());
        return bean;
    }
}
